package com.whut.work.user.controller;

import com.whut.work.base.model.Page;
import com.whut.work.user.model.User;
import com.whut.work.user.service.IUserNewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zouy on 17-3-15.
 */
@Controller
@RequestMapping("/user")
public class UserNewCtrl {

    @Autowired
    private IUserNewService userService;

    @RequestMapping(value="/getUserPageList",method= RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> getUserPageList(HttpServletRequest request, int currentPage, int pageSize, String blurName){
        Map<String,Object> returnMap = new HashMap<String,Object>();

        try {
            Page<User> userPage = userService.getUserPageList(currentPage,pageSize,blurName);

            returnMap.put("page", userPage);
            returnMap.put("success", true);
        } catch (Exception e) {
            returnMap.put("message", "异常：获取失败!");
            returnMap.put("success", false);
            e.printStackTrace();
        }
        return returnMap;
    }

    @RequestMapping(value="/getCoursePageListByUserId",method= RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> getCoursePageListByUserId(HttpServletRequest request, int currentPage, int pageSize, Integer userId){
        Map<String,Object> returnMap = new HashMap<String,Object>();

        try {
            Map<String,Object> result = userService.getCoursePageListByUserId(currentPage,pageSize,userId);

            returnMap.put("value", result.get("value"));
            returnMap.put("message", result.get("message"));
            returnMap.put("success", true);
        } catch (Exception e) {
            returnMap.put("message", "异常：获取失败!");
            returnMap.put("success", false);
            e.printStackTrace();
        }
        return returnMap;
    }

    @RequestMapping(value="/getInfoByUserId",method= RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> getInfoByUserId(HttpServletRequest request, Integer userId){
        Map<String,Object> returnMap = new HashMap<String,Object>();

        try {
            Map<String,Object> result = userService.getInfoByUserId(userId);

            returnMap.put("value", result.get("value"));
            returnMap.put("message", result.get("message"));
            returnMap.put("success", true);
        } catch (Exception e) {
            returnMap.put("message", "异常：获取失败!");
            returnMap.put("success", false);
            e.printStackTrace();
        }
        return returnMap;
    }

    @RequestMapping(value="/getTeacherPageList",method= RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> getTeacherPageList(HttpServletRequest request, int currentPage, int pageSize, Integer id){
        Map<String,Object> returnMap = new HashMap<String,Object>();

        try {
            Page<User> userPage = userService.getTeacherPageList(currentPage,pageSize,id);

            returnMap.put("page", userPage);
            returnMap.put("success", true);
        } catch (Exception e) {
            returnMap.put("message", "异常：获取失败!");
            returnMap.put("success", false);
            e.printStackTrace();
        }
        return returnMap;
    }

}
